package leetcode;

public class LC45 {
    public static void main(String[] args) {

    }

    public void flatten(TreeNode root) {
        TreeNode temp = root;
        while(temp != null){
            TreeNode left = temp.left;
            if (left != null){
                while(left.right != null){
                    left = left.right;
                }
                left.right = temp.right;
                temp.right = temp.left;
                temp.left = null;
            }
            temp = temp.right;
        }
    }
}
